package com.fescoservice.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.fescoservice.model.SeekerWorkExp;
import com.fescoservice.model.SeekerWorkExpId;

/**
 * A data access object (DAO) providing persistence and search support for
 * SeekerWorkExp entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.fescoservice.dao.SeekerWorkExp
 * @author MyEclipse Persistence Tools
 */

public class SeekerWorkExpDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(SeekerWorkExpDAO.class);
	// property constants
	public static final String START_YEAR = "startYear";
	public static final String START_MON = "startMon";
	public static final String END_YEAR = "endYear";
	public static final String END_MON = "endMon";
	public static final String COM_NAME = "comName";
	public static final String JOB_TYPE = "jobType";
	public static final String JOB_DEPT = "jobDept";
	public static final String JOB_TITLE = "jobTitle";
	public static final String JOB_DESC = "jobDesc";

	protected void initDao() {
		// do nothing
	}

	public void save(SeekerWorkExp transientInstance) {
		log.debug("saving SeekerWorkExp instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(SeekerWorkExp persistentInstance) {
		log.debug("deleting SeekerWorkExp instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public SeekerWorkExp findById(SeekerWorkExpId id) {
		log.debug("getting SeekerWorkExp instance with id: " + id);
		try {
			SeekerWorkExp instance = (SeekerWorkExp) getHibernateTemplate()
					.get("com.fescoservice.model.SeekerWorkExp", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(SeekerWorkExp instance) {
		log.debug("finding SeekerWorkExp instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding SeekerWorkExp instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from SeekerWorkExp as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByStartYear(Object startYear) {
		return findByProperty(START_YEAR, startYear);
	}

	public List findByStartMon(Object startMon) {
		return findByProperty(START_MON, startMon);
	}

	public List findByEndYear(Object endYear) {
		return findByProperty(END_YEAR, endYear);
	}

	public List findByEndMon(Object endMon) {
		return findByProperty(END_MON, endMon);
	}

	public List findByComName(Object comName) {
		return findByProperty(COM_NAME, comName);
	}

	public List findByJobType(Object jobType) {
		return findByProperty(JOB_TYPE, jobType);
	}

	public List findByJobDept(Object jobDept) {
		return findByProperty(JOB_DEPT, jobDept);
	}

	public List findByJobTitle(Object jobTitle) {
		return findByProperty(JOB_TITLE, jobTitle);
	}

	public List findByJobDesc(Object jobDesc) {
		return findByProperty(JOB_DESC, jobDesc);
	}

	public List findAll() {
		log.debug("finding all SeekerWorkExp instances");
		try {
			String queryString = "from SeekerWorkExp";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public SeekerWorkExp merge(SeekerWorkExp detachedInstance) {
		log.debug("merging SeekerWorkExp instance");
		try {
			SeekerWorkExp result = (SeekerWorkExp) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(SeekerWorkExp instance) {
		log.debug("attaching dirty SeekerWorkExp instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(SeekerWorkExp instance) {
		log.debug("attaching clean SeekerWorkExp instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static SeekerWorkExpDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (SeekerWorkExpDAO) ctx.getBean("SeekerWorkExpDAO");
	}
}